package com.konne.nightmare.FastPublicOpinion.ui.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.SizeUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.konne.nightmare.FastPublicOpinion.R;

/**
 * Create by ws.
 * on Data:2022/1/25  Time:下午 2:35.
 * description: ** .
 */
public class EditGroupNameDialog extends Dialog {
    private EditGroupNameListener editGroupNameListener;
    private int type;
    public EditGroupNameDialog(@NonNull Context context) {
        this(context,0);
    }
    public EditGroupNameDialog(@NonNull Context context,int type) {
        super(context);
        this.type=type;
    }
    public EditGroupNameDialog setEditGroupNameListener(EditGroupNameListener editGroupNameListener) {
        this.editGroupNameListener = editGroupNameListener;
        return this;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_edit_group_name);
        Window dialogWindow = getWindow();
        dialogWindow.setBackgroundDrawableResource(android.R.color.transparent);
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        lp.width = ViewGroup.LayoutParams.MATCH_PARENT;
        lp.height = SizeUtils.dp2px(290);
        dialogWindow.setAttributes(lp);
        dialogWindow.getDecorView().setPadding(0, 0, 0, 0);
        dialogWindow.setGravity(Gravity.BOTTOM);
        if(type==1){
            TextView tv_title=findViewById(R.id.tv_title);
            tv_title.setText("添加组");
        }
        EditText et_txt = findViewById(R.id.et_txt);
        findViewById(R.id.stv_cancel).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dismiss();
            }
        });
        findViewById(R.id.stv_submit).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (et_txt.getText().length() <= 0) {
                    ToastUtils.showShort("输入不能为空！");
                    return;
                }
                if(editGroupNameListener!=null){
                    editGroupNameListener.groupName(et_txt.getText().toString());
                }
                dismiss();
            }
        });

    }

    public interface EditGroupNameListener {
        void groupName(String txt);
    }
}
